package com.cskaoyan.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author stone
 * @date 2022/05/25 11:46
 */
@Component
public class CustomBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("beanName = " + beanName);
        // 可以做定制化的处理不
        if ("lifeCycleBean".equals(beanName)) {

        }
        if (bean instanceof User) {
            User user = (User) bean;
            user.setUsername("ligenli");
            return user;
        }
        //比如我传入的是lifeCycleBean 我可不可以返回lifeCycleBean的代理对象呢？

        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("BeanPostProcessor的after方法");
        return bean;
    }
}
